
(function () {
    'use strict';

    angular.module('KingAdmin.pages.sys.role')
        .controller('BindDevCtrl', BindDevCtrl);

    /** @ngInject */
    function BindDevCtrl($scope,$stateParams,$state, $uibModalInstance, RoleService,DevgroupService) {

        var kt = this;
        kt.role = {};

        if($stateParams.id){
            RoleService.getInfo({id:$stateParams.id},
                function (data) {
                    kt.role = data;
                })
        }

        DevgroupService.getSelectTree({roleId:$stateParams.id},function (data) {
            kt.treeData = data.result;
            kt.treeshow = true;
        });

        $scope.save = function () {
            var checked = kt.basicTree.jstree().get_checked(true);
            kt.role.devTree = [];
            angular.forEach(checked,function (c) {
                if (c.original.type == '2') {
                    kt.role.devTree.push(c.original);
                }
            });

            console.log(kt.role.devTree);

            RoleService.save(kt.role,function (data) {
                $uibModalInstance.close(true);
            });
        };

        kt.basicConfig = {
            core: {
                check_callback: true,
                worker: true
            },
            'types': {
                'default': {
                    'icon': false
                }
            },
            "checkbox" : {
                "keep_selected_style" : false
            },
            'plugins': ['types',"wholerow",'checkbox'],
            'version': 1
        };

    }

})();
